#include "node.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>



node* allocnode()
{
	return (node*) malloc(sizeof(node));
}

/*
	relie un noeud isole avec une liste de noeud
	e1 : noeud isole
	l : liste de ses freres
*/
	
void link_brothers(node * e1, node *l)
{
	e1->frere = l;
}

node* mkleafid(char* lex, entree* label, typeNoeud type) {
	node * res = allocnode();
	res->lexeme = lex;
	res->info = (info*)label;
	res -> type = type;
	res -> enfants = 0; //== null
	res-> frere = 0; //==null
}

node* mkleafcst(char* lex, entree* e, typeNoeud type) {
	node * res = allocnode();
	res->lexeme = lex;

	res-> info = (info*)e;

	res -> type = type;

	res -> enfants = 0; //== null
	res-> frere = 0; //==null
}


node* mknode(char* lex, entree* label, typeNoeud type, void* infos, node* enfants, node * frere) { 
	node * res = allocnode();
	res->lexeme = lex;
	res->info = (info*)label;
	res->type = type;
	res->infos = infos;
	res->enfants = enfants;
	res->frere = frere;
}

void decoderTypeNoeud(typeNoeud t) {
	
	switch(t)
	{
		case TPROGRAM : printf("-------------------------------type TPROGRAM\n"); break;
		case TMAIN : printf("-------------------------------type TMAIN\n"); break;
		case TFUNCTION : printf("-------------------------------type TFUNCTION\n"); break;
		case TPROCEDURE : printf("-------------------------------type TPROCEDURE\n"); break;
		case TCALLFUN : printf("-------------------------------type TCALLFUN\n"); break;
		case TRETURN : printf("-------------------------------type TRETURN\n"); break;
		case TBLOC : printf("-------------------------------type TBLOC\n"); break;
		case TIF : printf("-------------------------------type TIF\n"); break;
		case TWHILE : printf("-------------------------------type TWHILE\n"); break;
		case TOPBINAIRE : printf("-------------------------------type TOPBINAIRE\n"); break;
		case TNON : printf("-------------------------------type TNON\n"); break;
		case TMOINSUNAIRE : printf("-------------------------------type TMOINSUNAIRE\n"); break;
		case TARRAY : printf("-------------------------------type TARRAY\n"); break;
		case TVAR : printf("-------------------------------type TVAR\n"); break;
		case TCST : printf("-------------------------------type TCST\n"); break;
	}
}
